


#ifndef BC_VECTOR2D_H
#define BC_VECTOR2D_H

#include <cmath>


class BCVector2d
{

	/****************************************************************************************
	* A basic 2d vector implementation. Should be extended , but not neccesarily , as it does the job...
	*****************************************************************************************/

	public :

		/***************************************************************
		* CONSTRUCTORS :
		****************************************************************/

		// default constructor of BCVector2d
		BCVector2d();

		// constructs a 2d vector from 2 values :
		BCVector2d(float x , float y);

		// constructs a 2d vector from an another vector :
		BCVector2d(const BCVector2d& vect);

		/*****************************************************************
		* SETTERS :
		******************************************************************/

		// sets the vectors values :
		void set(float x , float y);

		/*****************************************************************
		* GETTERS :
		******************************************************************/
		
		// converts the battle city vector to a D3D vector
		D3DXVECTOR2 getD3DVector2() const;



		/*****************************************************************
		* MATHS :
		******************************************************************/

		// returns the dot product of two vectors 
		float dotProduct(const BCVector2d& vect);

		// normalizes the vector :
		void normalize();

		// returns the normal vector (the vector isn't normalized !)
		BCVector2d getNormalVector();

		// returns the magnitude of the vector :
		float getMagnitude();


		/******************************************************************
		* OPERATORS :
		******************************************************************/

		// the + operator :
		BCVector2d operator+(const BCVector2d &vect) const;
		
		// the - operator :
		BCVector2d operator-(const BCVector2d &vect) const;

		// the += operator :
		void operator += (const BCVector2d &vect);

		// the -= operator :
		void operator -= (const BCVector2d &vect);


		void operator = (const D3DXVECTOR2 &vect);
		



		/******************************************************************
		* CLASS MEMBERS :
		******************************************************************/

		float x , y;


};


/*****************************************************************************************************
* INLINE DEFINITIONS :
******************************************************************************************************/



inline BCVector2d::BCVector2d()
{
	x = y = 1.0f;
}


inline BCVector2d::BCVector2d(float x, float y)
{
	this->x = x;
	this->y = y;
}


inline BCVector2d::BCVector2d(const BCVector2d &vect)
{
	this->x = vect.x;
	this->y = vect.y;
}



inline float BCVector2d::dotProduct(const BCVector2d &vect)
{
	return (this->x * vect.y) - (this->y * vect.x);
}


inline float BCVector2d::getMagnitude()
{
	return sqrtf(x * x + y * y);
}


inline void BCVector2d::normalize()
{
	float mag = sqrtf(x* x + y * y);
	this->x = x / mag;
	this->y = y / mag;
}

inline BCVector2d BCVector2d::getNormalVector()
{
	float mag = sqrtf(x* x + y * y);
	return  BCVector2d(x / mag , y / mag);
}


inline void BCVector2d::set(float x, float y)
{
	this->x = x;
	this->y = y;
}


inline D3DXVECTOR2 BCVector2d::getD3DVector2() const
{
	return D3DXVECTOR2(x,y);
}





inline BCVector2d BCVector2d::operator +(const BCVector2d &vect) const
{
	return BCVector2d(x + vect.x, y + vect.y);
}


inline BCVector2d BCVector2d::operator -(const BCVector2d &vect) const
{
	return BCVector2d(x - vect.x, y - vect.y);
}

inline void BCVector2d::operator += (const BCVector2d &vect)
{
	this->x += vect.x;
	this->y += vect.y;
}


inline void BCVector2d::operator -= (const BCVector2d &vect)
{
	this->x -= vect.x;
	this->y -= vect.y;
}

inline void BCVector2d::operator =(const D3DXVECTOR2 &vect)
{
	x = vect.x;
	y = vect.y;
}






#endif










